package com.wn.common.provider

import android.content.Context
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.launcher.ARouter
import com.wn.common.constant.LOGIN_SERVICE_LOGIN
import com.wn.common.service.ILoginService

/**
 * @Author: wn
 * @Date: 2025/6/19 17:23
 * @Description: LoginService提供类，对外提供相关能力
 * 任意模块就能通过 LoginServiceProvider 提供的 --> LoginService，使用对外暴露的能力
 */
object LoginServiceProvider {
  
  @Autowired(name = LOGIN_SERVICE_LOGIN)
  lateinit var loginService: ILoginService

  init {
    ARouter.getInstance().inject(this)
  }

  /**
   * 跳转登录页
   * @param context Context
   */
  fun toLogin(context: Context) = loginService.toLogin(context)

  /**
   * 跳转隐私协议
   * @param context Context
   */
  fun readPolicy(context: Context) = loginService.readPolicy(context)

  /**
   * 登出
   * @param context Context
   * @param lifecycleOwner LifecycleOwner?
   * @param observer Observer<Boolean>
   */
  fun logout(
    context: Context,
    lifecycleOwner: LifecycleOwner?,
    observer: Observer<Boolean>,
  ) = loginService.logout(context, lifecycleOwner, observer)
}